<template>
  <div class="select-container">
    <!-- 搜索表单 -->
    <el-form :model="queryParams" ref="queryForm" :inline="true" class="search-form">
      <el-form-item label="昵称" prop="nickname">
        <el-input
          v-model="queryParams.nickname"
          placeholder="请输入昵称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格 -->
    <el-table
      v-loading="loading"
      :data="SlCustomList"
      height="220"
      @row-click="handleRowClick">
      <el-table-column label="昵称" align="center" prop="nickname" />
      <el-table-column label="头像" align="center" >
        <template slot-scope="scope">
         <img :src="scope.row.avatarurl" alt="图片描述" width="50" height="50" />
       </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="phone" width="120" />
      <el-table-column label="操作" align="center" width="80">
        <template slot-scope="scope">
          <el-button type="text" @click.stop="handleSelect(scope.row)">选择</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
      small
    />
  </div>
</template>

<style lang="scss" scoped>
.select-container {
  padding: 0;
  
  .search-form {
    margin-bottom: 8px;
    padding: 0;
    
    .el-form-item {
      margin-bottom: 8px;
      margin-right: 8px;
      
      &:last-child {
        margin-right: 0;
      }
    }
  }
  
  .el-table {
    margin: 0;
    
    ::v-deep .el-table__body-wrapper {
      min-height: 100px;
    }
  }
  
  .pagination-container {
    padding: 8px 0 0;
    text-align: right;
  }
}
</style>

<script>
import { listSlCustom } from "@/api/projects/SlCustom";

export default {
  name: "SlCustom",
  dicts: ['sys_user_sex','user_flog'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 森理会员表格数据
      SlCustomList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nickname: null,
        phone: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询森理会员列表 */
    getList() {
      this.loading = true;
      listSlCustom(this.queryParams).then(response => {
        this.SlCustomList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        openId: null,
        nickname: null,
        gender: null,
        avatarurl: null,
        city: null,
        phone: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 处理行点击 */
    handleRowClick(row) {
      this.handleSelect(row);
    },
    /** 处理选择 */
    handleSelect(row) {
      this.$emit('select', {
        name: row.nickname,
        phone: row.phone,
        customId: row.id,
        customType: 2 // 标记为微信会员
      });
    }
  }
};
</script>
  